/**
 * 定义季度报表模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.sw.reportData.quarterDataManager', ['water.apps.common.report.reportFormBase',
	                                                                          'water.common.dateUtil']);
	
	module.controller('quarterDataMonthManagerController',function($scope,$monitorDataService,$controller,$dateUtil){

		var control = $controller("commonReportFormController",{$scope:$scope});
		
		/**
		 * 年选择下拉数据
		 */
		$scope.yearlist = [{name:'2016年',value:2016},{name:'2017年',value:2017}];
		/**
		 * 选择的年份
		 */
		$scope.selectYear;
		/**
		 * 选择的季度
		 */
		$scope.selectQuarter;
		/**
		 * 季度选择下拉数据
		 */
		$scope.quarterslist=[
		                 {name:"第1季度",value:1},
		                 {name:"第2季度",value:2},
		                 {name:"第3季度",value:3},
		                 {name:"第4季度",value:4}
		                ];
		
		$scope.dataAPIName = 'getQuarterReport';
		$scope.dataExportAPIName = "exportQuarterExcel";
		/**
		 * 季度选择事件
		 */
		$scope.onQuarterSelected = function(){
			$scope.getQueryObject();
		}
		/**
		 * 获取查询参数
		 */
		$scope.getQueryObject = function(){
			var startMonth = ($scope.selectQuarter - 1) * 3 + 1;
			var startDateStr = $scope.selectYear + "-" + startMonth + "-1 00:00:00";
			var startDate = $dateUtil.createDate(startDateStr);
			var endDate = $dateUtil.addDay($dateUtil.addMonth(startDate,3),-1);
			var endDateStr = $dateUtil.formatDate(endDate);
			
			var parmsStr = $scope.selectedModel.parmToChecksStr;
			var queryObject = {
					"MN":$scope.selectedModel.MN,
					"PARMS":parmsStr,
					"START":startDateStr,
					"END":endDateStr
				};
			return queryObject;
		}
		
		function _init(){
			var date = new Date();
			var month = date.getMonth() + 1;
			if(month <= 3){
				$scope.selectQuarter = 1;
			}
			else if(month <= 6){
				$scope.selectQuarter = 2;
			}
			else if(month <= 9){
				$scope.selectQuarter = 3;
			}
			else if(month <= 12){
				$scope.selectQuarter = 4;
			}
			$scope.selectYear = date.getFullYear();
		}
		
		_init();
		
	});
}(window, angular));